package com.devunion.bogdan.view.project.actions;

import com.devunion.bogdan.model.project.*;
import com.devunion.bogdan.view.project.dialogs.PaperDialog;
import com.devunion.bogdan.view.project.dialogs.PaperDialogAction;
import com.devunion.bogdan.view.util.DialogHelper;

import java.awt.event.ActionEvent;

/**
 * @author Viktar Liaskovich
 */
public class AddPaperAction extends AbstractProjectAction{
    private PaperDialog paperDialog;

    public boolean isApplicable(Paper e) {
        return false;
    }

    public AddPaperAction(PaperType paperType) {
         paperDialog = new PaperDialog(DialogHelper.getMainFrame(), PaperDialogAction.ADD, paperType);
    }

    public void actionPerformed(ActionEvent e) {

        paperDialog.setPaperInfo(null);
        paperDialog.setVisible(true);

        if (paperDialog.getPaperInfo() == null) {
            return;
        }

        Paper book = new Paper();
        book.setInfo(paperDialog.getPaperInfo());

        ProjectManager.getInstance().getCurrentProject().addEntry(book);
    }
}
